package com.linkme2night.view.login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

import com.facebook.Session;
import com.linkme2night.R;
import com.linkme2night.controller.FacebookController;
import com.linkme2night.controller.FrontController;
import com.linkme2night.model.SocialNetwork_enum;

public class ChooseLoginActivity extends Activity implements OnClickListener {

	private Button btn_facebook;
	private Button btn_gmail;
	private FacebookController fbcont;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_choose_login);

		fbcont = new FacebookController(this,savedInstanceState);
		

		btn_facebook = (Button) findViewById(R.id.btn_facebook);
		btn_gmail = (Button) findViewById(R.id.btn_gmail);

		btn_facebook.setOnClickListener(this);
		btn_gmail.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {

		if (v.getId() == btn_facebook.getId()) {

			fbcont.login();

		} else {
			//DUMMY
			FrontController fController= new FrontController();
			fController.openMenu(this, SocialNetwork_enum.GMAIL);

			Toast t = Toast.makeText(getApplicationContext(), "GMAIL ", 2);
			t.show();
		}

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		Session.getActiveSession().onActivityResult(this, requestCode,
				resultCode, data);

	}

	@Override
	public void onStart() {

		super.onStart();
		Session.getActiveSession().addCallback(fbcont.getStatusCallback());
	}

	@Override
	public void onStop() {
		super.onStop();
		Session.getActiveSession().removeCallback(fbcont.getStatusCallback());
	}

	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		Session session = Session.getActiveSession();
		Session.saveSession(session, outState);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.choose_login, menu);
		return true;
	}
}
